<template>
  <div class="works-main">
    <div class="works-main-banner">
      <div class="works-main-banner-left">
        <div class="works-main-banner-left-con">
          <p><img src="./works_img/图层573.png" alt="" /></p>
        </div>
      </div>
      <div class="works-main-banner-right">
        <div class="works-main-banner-right-con">
          <p class="works-main-banner-right-con-1">
            <img src="./works_img/学员作品.png" alt="" />
          </p>
          <div class="works-main-banner-right-con-2">
            精心设计 · 学生作品展示
          </div>
          <span class="works-main-banner-right-con-3"></span>
          <p class="works-main-banner-right-con-4">了解详情</p>
        </div>
      </div>
    </div>
    <div class="works-main-tab-wrap">
      <div class="works-main-tab">
        <div class="works-main-tab-title">
          <span @click="changeType((num = 0))" :class="{ active: num == 0 }">
            全部作品
            <p :class="{ line: num == 0 }"><b></b></p>
          </span>
          <span @click="changeType((num = 1))" :class="{ active: num == 1 }">
            HTML5
            <p :class="{ line: num == 1 }"><b></b></p>
          </span>
          <span @click="changeType((num = 2))" :class="{ active: num == 2 }">
            UI
            <p :class="{ line: num == 2 }"><b></b></p>
          </span>
          <span @click="changeType((num = 3))" :class="{ active: num == 3 }">
            Java
            <p :class="{ line: num == 3 }"><b></b></p>
          </span>
          <span @click="changeType((num = 4))" :class="{ active: num == 4 }">
            Python
            <p :class="{ line: num == 4 }"><b></b></p>
          </span>
        </div>
        <div class="works-main-tab-con">
          <div v-show="num == 0">
            <swiper ref="mySwiper" :options="swiperOptions">
              <swiper-slide v-for="(item, index) in filterData" :key="index">
                <img :src="'https://itdahua.com/' + item.image" alt="" />
                <p>{{ item.title }}</p>
              </swiper-slide>
            </swiper>
            <div class="swiper-pagination"></div>
          </div>
          <div v-show="num == 1">
            <swiper ref="mySwiper" :options="swiperOptions">
              <swiper-slide v-for="(item, index) in filterData" :key="index">
                <img :src="'https://itdahua.com/' + item.image" alt="" />
                <p>{{ item.title }}</p>
              </swiper-slide>
            </swiper>
            <!-- <div class="swiper-pagination"></div> -->
          </div>
          <div v-show="num == 2">
            <swiper ref="mySwiper" :options="swiperOptions">
              <swiper-slide v-for="(item, index) in filterData" :key="index">
                <img :src="'https://itdahua.com/' + item.image" alt="" />
                <p>{{ item.title }}</p>
              </swiper-slide>
            </swiper>
            <!-- <div class="swiper-pagination"></div> -->
          </div>
          <div v-show="num == 3">
            <swiper ref="mySwiper" :options="swiperOptions">
              <swiper-slide v-for="(item, index) in filterData" :key="index">
                <img :src="'https://itdahua.com/' + item.image" alt="" />
                <p>{{ item.title }}</p>
              </swiper-slide>
            </swiper>
            <!-- <div class="swiper-pagination"></div> -->
          </div>
          <div v-show="num == 4">
            <swiper ref="mySwiper" :options="swiperOptions">
              <swiper-slide v-for="(item, index) in filterData" :key="index">
                <img :src="'https://itdahua.com/' + item.image" alt="" />
                <p>{{ item.title }}</p>
              </swiper-slide>
            </swiper>
            <!-- <div class="swiper-pagination"></div> -->
          </div>

          <div class="swiper-button-next">
            <img src="./works_img/右.png" alt="" />
          </div>
          <div class="swiper-button-prev">
            <img src="./works_img/左.png" alt="" />
          </div>
        </div>
      </div>
    </div>
    <Footer></Footer>
  </div>
</template>

<script>
import { Swiper, SwiperSlide, directive } from "vue-awesome-swiper";
import "swiper/swiper-bundle.css";
import { Grid, Navigation, Pagination } from "swiper";
import Footer from '@/components/footer/Footer.vue'
import axios from "axios";
export default {
  components: {
    Swiper,
    SwiperSlide,
    Footer
  },
  directives: {
    swiper: directive,
  },
  data() {
    return {
      listData: [],
      filterData: [],
      num: 0,
      swiperOptions: {
        modules: [Grid, Navigation, Pagination],
        // 设置容器能够同时显示slide数量
        slidesPerView: 4,
        // slide之间的间隔
        spaceBetween: 30,
        grid: {
          rows: 3,
          fill: "row",
        },
        pagination: {
          el: ".swiper-pagination",
          clickable: true,
          renderBullet: function (index, className) {
            return '<span class="' + className + '">' + (index + 1) + "</span>";
          },
        },
        navigation: {
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev",
        },
      },
    };
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.$swiper;
    },
  },
  async created() {
    let res = await axios.get("api/studentopus/list");
    //   console.log('res',res);
    console.log("res", res.data.data);
    this.listData = res.data.data;
    this.changeType(0)
  },
  methods: {
    changeType(num) {
      if (this.listData) {
        if (num == 0) {
          this.filterData = this.listData;
          console.log("11", this.listData);
        } else if (num == 1) {
          this.filterData = this.listData.filter((item) => item.cid == 7);
          console.log("22", this.listData);
        } else if (num == 2) {
          this.filterData = this.listData.filter((item) => item.cid == 9);
          console.log("33", this.listData);
        } else if (num == 3) {
          this.filterData = this.listData.filter((item) => item.cid == 8);
          console.log("44", this.listData);
        } else if (num == 4) {
          this.filterData = this.listData.filter((item) => item.cid == 10);
          console.log("55", this.listData);
        }
      }
    },
  },
  mounted() {
    // console.log("Current Swiper instance object", this.swiper);
    this.swiper.slideTo(0, 1000, false);
  },
};
</script>

<style lang="scss" scoped>
.works-main {
  min-width: 1200px;
  .works-main-banner {
    width: 100%;
    min-width: 1200px;
    height: 518px;
    position: relative;
    display: flex;
    .works-main-banner-left {
      background: url(./works_img/未标题-1.jpg) no-repeat;
      width: 53.5%;
      height: 518px;
      background-size: cover;
      .works-main-banner-left-con {
        position: absolute;
      }
    }
    .works-main-banner-right {
      background: url(./works_img/图层512.jpg) no-repeat;
      width: 46.5%;
      height: 518px;
      background-size: cover;
      .works-main-banner-right-con {
        padding: 73px 0 215px 73px;
        box-sizing: border-box;
        .works-main-banner-right-con-1 {
          text-align: left;
        }
        .works-main-banner-right-con-2 {
          margin: 19px 0 30px;
          font-size: 28px;
          color: #fff;
          text-align: left;
        }
        .works-main-banner-right-con-3 {
          display: block;
          width: 284px;
          height: 1px;
          background: #fff;
          margin-bottom: 49px;
        }
        .works-main-banner-right-con-4 {
          width: 99px;
          height: 37px;
          border: 2px solid #fff;
          line-height: 37px;
          text-align: center;
          font-style: 16px;
          color: #fff;
        }
      }
    }
  }
  .works-main-tab-wrap {
    min-width: 1200px;
    .works-main-tab {
      margin: auto;
      width: 1200px;
      .works-main-tab-title {
        font-size: 20px;
        color: #999;
        margin-bottom: 40px;
        padding-top: 63px;
        .active {
          color: #1f8ceb;
          font-weight: 700;
        }
        span {
          font-weight: 400;
          padding-bottom: 22px;
          width: 240px;
          text-align: center;
          display: inline-block;
          border-bottom: 2px solid #e5e5e5;
          position: relative;
          font-size: 20px;
          .line {
            width: 240px;
            border-bottom: 2px solid #1f8ceb;
            text-align: center;
            position: absolute;
            bottom: -1px;
            b {
              position: absolute;
              top: -8px;
              border-left: 7px solid transparent;
              border-right: 7px solid transparent;
              border-bottom: 10px solid #1f8ceb;
            }
          }
        }
      }
      .works-main-tab-con {
        width: 1200px;
        position: relative;
        overflow: hidden;
        padding-bottom: 147px;
        .swiper-pagination {
          font-size: 0;
          bottom: 61px;
          text-align: center;
          width: auto;
          left: 50%;
          transform: translate(-50%);
        }

        .swiper-slide {
          text-align: center;
          font-size: 18px;
          background: #fff;
          border: 2px solid #e5e5e5;
          border-radius: 11px;
          box-sizing: border-box;
          width: 280px;
          height: 210px;
          margin-bottom: 4px;
          img {
            border-top-left-radius: 10px;
            border-top-right-radius: 10px;
            width: 100%;
            height: 166px;
          }
          p {
            font-weight: 400;
            font-size: 14px;
            color: #333;
            text-align: center;
            line-height: 36px;
          }
        }
        .swiper-button-prev {
          opacity: 0.5;
          position: absolute;
          width: 33px;
          height: 33px;
          background-color: #dedede;
          bottom: 61px;
          right: auto;
          left: 43%;
          top: auto;
          outline: none;
        }
        .swiper-button-next {
          opacity: 0.5;
          position: absolute;
          width: 33px;
          height: 33px;
          background-color: #dedede;
          bottom: 61px;
          left: auto;
          right: 43%;
          top: auto;
          outline: none;
        }
        .swiper-button-prev:after,
        .swiper-button-next:after {
          font-size: inherit;
          display: none;
        }
      }
    }
  }
}
.works-main-tab-con ::v-deep .swiper-pagination-bullet {
  width: 33px;
  height: 33px;
  background-color: #dedede;
  text-align: center;
  line-height: 33px;
  margin: 0 3px;
  border-radius: 0;
  font-size: 14px;
  opacity: 1;
}
.works-main-tab-con ::v-deep .swiper-pagination-bullet-active {
  background-color: #1f8ceb;
  color: #fff;
}
</style>
